﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类ServiceChargeBaseInfo。
    /// </summary>
    public class ServiceChargeBaseInfo
    {
        public ServiceChargeBaseInfo()
        { }
        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_ServiceCharge_BaseInfo(");
            strSql.Append("ReceiptId,ReceiptCode,ReceiptCityId,ReceiptCity,ReceiptCompanyId,ReceiptCompany,ReceiptDepartId,ReceiptDepart,ReceiptEmployeeId,ReceiptEmployee,BusinessType,ReceiptMoneyName,ContractId,ContractCode,HouseAddress,CustomerName,Mobile,Phone,CustomerAddress,ZipCode,GetedTime,GetedMoney,ReceiptMemo,AddEmployeeId,AddEmployee,AddTime,Status,UnusedReason,UnusedDate,UnusedPersonId,UnusedPerson,IsGeted1,IsGeted2,FinMemo,IsConfirmed,LastConfirmeTime,LastConfirmeEmpId,LastConfirmeEmployee,ConfireGetedTime,FinishFlag,LastPrintTime,LastPrintEmpId,LastPrintEmp,TotalPrintCount)");

            strSql.Append(" values (");
            strSql.Append("@ReceiptId,@ReceiptCode,@ReceiptCityId,@ReceiptCity,@ReceiptCompanyId,@ReceiptCompany,@ReceiptDepartId,@ReceiptDepart,@ReceiptEmployeeId,@ReceiptEmployee,@BusinessType,@ReceiptMoneyName,@ContractId,@ContractCode,@HouseAddress,@CustomerName,@Mobile,@Phone,@CustomerAddress,@ZipCode,@GetedTime,@GetedMoney,@ReceiptMemo,@AddEmployeeId,@AddEmployee,@AddTime,@Status,@UnusedReason,@UnusedDate,@UnusedPersonId,@UnusedPerson,@IsGeted1,@IsGeted2,@FinMemo,@IsConfirmed,@LastConfirmeTime,@LastConfirmeEmpId,@LastConfirmeEmployee,@ConfireGetedTime,@FinishFlag,@LastPrintTime,@LastPrintEmpId,@LastPrintEmp,@TotalPrintCount)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ReceiptId", DbType.Guid, model.ReceiptId);
            db.AddInParameter(dbCommand, "ReceiptCode", DbType.AnsiString, model.ReceiptCode);
            db.AddInParameter(dbCommand, "ReceiptCityId", DbType.Guid, model.ReceiptCityId);
            db.AddInParameter(dbCommand, "ReceiptCity", DbType.AnsiString, model.ReceiptCity);
            db.AddInParameter(dbCommand, "ReceiptCompanyId", DbType.Guid, model.ReceiptCompanyId);
            db.AddInParameter(dbCommand, "ReceiptCompany", DbType.AnsiString, model.ReceiptCompany);
            db.AddInParameter(dbCommand, "ReceiptDepartId", DbType.Guid, model.ReceiptDepartId);
            db.AddInParameter(dbCommand, "ReceiptDepart", DbType.AnsiString, model.ReceiptDepart);
            db.AddInParameter(dbCommand, "ReceiptEmployeeId", DbType.Guid, model.ReceiptEmployeeId);
            db.AddInParameter(dbCommand, "ReceiptEmployee", DbType.AnsiString, model.ReceiptEmployee);
            db.AddInParameter(dbCommand, "BusinessType", DbType.Int32, model.BusinessType);
            db.AddInParameter(dbCommand, "ReceiptMoneyName", DbType.AnsiString, model.ReceiptMoneyName);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode);
            db.AddInParameter(dbCommand, "HouseAddress", DbType.AnsiString, model.HouseAddress);
            db.AddInParameter(dbCommand, "CustomerName", DbType.AnsiString, model.CustomerName);
            db.AddInParameter(dbCommand, "Mobile", DbType.AnsiString, model.Mobile);
            db.AddInParameter(dbCommand, "Phone", DbType.AnsiString, model.Phone);
            db.AddInParameter(dbCommand, "CustomerAddress", DbType.AnsiString, model.CustomerAddress);
            db.AddInParameter(dbCommand, "ZipCode", DbType.AnsiString, model.ZipCode);
            db.AddInParameter(dbCommand, "GetedTime", DbType.DateTime, model.GetedTime);
            db.AddInParameter(dbCommand, "GetedMoney", DbType.Decimal, model.GetedMoney);
            db.AddInParameter(dbCommand, "ReceiptMemo", DbType.AnsiString, model.ReceiptMemo);
            db.AddInParameter(dbCommand, "AddEmployeeId", DbType.Guid, model.AddEmployeeId);
            db.AddInParameter(dbCommand, "AddEmployee", DbType.AnsiString, model.AddEmployee);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.AddInParameter(dbCommand, "UnusedReason", DbType.AnsiString, model.UnusedReason);
            db.AddInParameter(dbCommand, "UnusedDate", DbType.DateTime, model.UnusedDate);
            db.AddInParameter(dbCommand, "UnusedPersonId", DbType.Guid, model.UnusedPersonId);
            db.AddInParameter(dbCommand, "UnusedPerson", DbType.AnsiString, model.UnusedPerson);
            db.AddInParameter(dbCommand, "IsGeted1", DbType.Boolean, model.IsGeted1);
            db.AddInParameter(dbCommand, "IsGeted2", DbType.Boolean, model.IsGeted2);
            db.AddInParameter(dbCommand, "FinMemo", DbType.AnsiString, model.FinMemo);
            db.AddInParameter(dbCommand, "IsConfirmed", DbType.Boolean, model.IsConfirmed);
            db.AddInParameter(dbCommand, "LastConfirmeTime", DbType.DateTime, model.LastConfirmeTime);
            db.AddInParameter(dbCommand, "LastConfirmeEmpId", DbType.Guid, model.LastConfirmeEmpId);
            db.AddInParameter(dbCommand, "LastConfirmeEmployee", DbType.AnsiString, model.LastConfirmeEmployee);
            db.AddInParameter(dbCommand, "ConfireGetedTime", DbType.DateTime, model.ConfireGetedTime);
            db.AddInParameter(dbCommand, "FinishFlag", DbType.Int32, model.FinishFlag);
            db.AddInParameter(dbCommand, "LastPrintTime", DbType.DateTime, model.LastPrintTime);
            db.AddInParameter(dbCommand, "LastPrintEmpId", DbType.Guid, model.LastPrintEmpId);
            db.AddInParameter(dbCommand, "LastPrintEmp", DbType.AnsiString, model.LastPrintEmp);
            db.AddInParameter(dbCommand, "TotalPrintCount", DbType.Int32, model.TotalPrintCount);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_ServiceCharge_BaseInfo set ");
            strSql.Append("ReceiptCode=@ReceiptCode,");
            strSql.Append("ReceiptCityId=@ReceiptCityId,");
            strSql.Append("ReceiptCity=@ReceiptCity,");
            strSql.Append("ReceiptCompanyId=@ReceiptCompanyId,");
            strSql.Append("ReceiptCompany=@ReceiptCompany,");
            strSql.Append("ReceiptDepartId=@ReceiptDepartId,");
            strSql.Append("ReceiptDepart=@ReceiptDepart,");
            strSql.Append("ReceiptEmployeeId=@ReceiptEmployeeId,");
            strSql.Append("ReceiptEmployee=@ReceiptEmployee,");
            strSql.Append("BusinessType=@BusinessType,");
            strSql.Append("ReceiptMoneyName=@ReceiptMoneyName,");
            strSql.Append("ContractId=@ContractId,");
            strSql.Append("ContractCode=@ContractCode,");
            strSql.Append("HouseAddress=@HouseAddress,");
            strSql.Append("CustomerName=@CustomerName,");
            strSql.Append("Mobile=@Mobile,");
            strSql.Append("Phone=@Phone,");
            strSql.Append("CustomerAddress=@CustomerAddress,");
            strSql.Append("ZipCode=@ZipCode,");
            strSql.Append("GetedTime=@GetedTime,");
            strSql.Append("GetedMoney=@GetedMoney,");
            strSql.Append("ReceiptMemo=@ReceiptMemo,");
            strSql.Append("AddEmployeeId=@AddEmployeeId,");
            strSql.Append("AddEmployee=@AddEmployee,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("Status=@Status,");
            strSql.Append("UnusedReason=@UnusedReason,");
            strSql.Append("UnusedDate=@UnusedDate,");
            strSql.Append("UnusedPersonId=@UnusedPersonId,");
            strSql.Append("UnusedPerson=@UnusedPerson,");
            strSql.Append("IsGeted1=@IsGeted1,");
            strSql.Append("IsGeted2=@IsGeted2,");
            strSql.Append("FinMemo=@FinMemo,");
            strSql.Append("IsConfirmed=@IsConfirmed,");
            strSql.Append("LastConfirmeTime=@LastConfirmeTime,");
            strSql.Append("LastConfirmeEmpId=@LastConfirmeEmpId,");
            strSql.Append("LastConfirmeEmployee=@LastConfirmeEmployee,");
            strSql.Append("ConfireGetedTime=@ConfireGetedTime,");
            strSql.Append("FinishFlag=@FinishFlag,");
            strSql.Append("LastPrintTime=@LastPrintTime,");
            strSql.Append("LastPrintEmpId=@LastPrintEmpId,");
            strSql.Append("LastPrintEmp=@LastPrintEmp,");
            strSql.Append("TotalPrintCount=@TotalPrintCount");
            strSql.Append(" where ReceiptId=@ReceiptId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ReceiptId", DbType.Guid, model.ReceiptId);
            db.AddInParameter(dbCommand, "ReceiptCode", DbType.AnsiString, model.ReceiptCode);
            db.AddInParameter(dbCommand, "ReceiptCityId", DbType.Guid, model.ReceiptCityId);
            db.AddInParameter(dbCommand, "ReceiptCity", DbType.AnsiString, model.ReceiptCity);
            db.AddInParameter(dbCommand, "ReceiptCompanyId", DbType.Guid, model.ReceiptCompanyId);
            db.AddInParameter(dbCommand, "ReceiptCompany", DbType.AnsiString, model.ReceiptCompany);
            db.AddInParameter(dbCommand, "ReceiptDepartId", DbType.Guid, model.ReceiptDepartId);
            db.AddInParameter(dbCommand, "ReceiptDepart", DbType.AnsiString, model.ReceiptDepart);
            db.AddInParameter(dbCommand, "ReceiptEmployeeId", DbType.Guid, model.ReceiptEmployeeId);
            db.AddInParameter(dbCommand, "ReceiptEmployee", DbType.AnsiString, model.ReceiptEmployee);
            db.AddInParameter(dbCommand, "BusinessType", DbType.Int32, model.BusinessType);
            db.AddInParameter(dbCommand, "ReceiptMoneyName", DbType.AnsiString, model.ReceiptMoneyName);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "ContractCode", DbType.AnsiString, model.ContractCode);
            db.AddInParameter(dbCommand, "HouseAddress", DbType.AnsiString, model.HouseAddress);
            db.AddInParameter(dbCommand, "CustomerName", DbType.AnsiString, model.CustomerName);
            db.AddInParameter(dbCommand, "Mobile", DbType.AnsiString, model.Mobile);
            db.AddInParameter(dbCommand, "Phone", DbType.AnsiString, model.Phone);
            db.AddInParameter(dbCommand, "CustomerAddress", DbType.AnsiString, model.CustomerAddress);
            db.AddInParameter(dbCommand, "ZipCode", DbType.AnsiString, model.ZipCode);
            db.AddInParameter(dbCommand, "GetedTime", DbType.DateTime, model.GetedTime);
            db.AddInParameter(dbCommand, "GetedMoney", DbType.Decimal, model.GetedMoney);
            db.AddInParameter(dbCommand, "ReceiptMemo", DbType.AnsiString, model.ReceiptMemo);
            db.AddInParameter(dbCommand, "AddEmployeeId", DbType.Guid, model.AddEmployeeId);
            db.AddInParameter(dbCommand, "AddEmployee", DbType.AnsiString, model.AddEmployee);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "Status", DbType.Int32, model.Status);
            db.AddInParameter(dbCommand, "UnusedReason", DbType.AnsiString, model.UnusedReason);
            db.AddInParameter(dbCommand, "UnusedDate", DbType.DateTime, model.UnusedDate);
            db.AddInParameter(dbCommand, "UnusedPersonId", DbType.Guid, model.UnusedPersonId);
            db.AddInParameter(dbCommand, "UnusedPerson", DbType.AnsiString, model.UnusedPerson);
            db.AddInParameter(dbCommand, "IsGeted1", DbType.Boolean, model.IsGeted1);
            db.AddInParameter(dbCommand, "IsGeted2", DbType.Boolean, model.IsGeted2);
            db.AddInParameter(dbCommand, "FinMemo", DbType.AnsiString, model.FinMemo);
            db.AddInParameter(dbCommand, "IsConfirmed", DbType.Boolean, model.IsConfirmed);
            db.AddInParameter(dbCommand, "LastConfirmeTime", DbType.DateTime, model.LastConfirmeTime);
            db.AddInParameter(dbCommand, "LastConfirmeEmpId", DbType.Guid, model.LastConfirmeEmpId);
            db.AddInParameter(dbCommand, "LastConfirmeEmployee", DbType.AnsiString, model.LastConfirmeEmployee);
            db.AddInParameter(dbCommand, "ConfireGetedTime", DbType.DateTime, model.ConfireGetedTime);
            db.AddInParameter(dbCommand, "FinishFlag", DbType.Int32, model.FinishFlag);
            db.AddInParameter(dbCommand, "LastPrintTime", DbType.DateTime, model.LastPrintTime);
            db.AddInParameter(dbCommand, "LastPrintEmpId", DbType.Guid, model.LastPrintEmpId);
            db.AddInParameter(dbCommand, "LastPrintEmp", DbType.AnsiString, model.LastPrintEmp);
            db.AddInParameter(dbCommand, "TotalPrintCount", DbType.Int32, model.TotalPrintCount);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid ReceiptId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_ServiceCharge_BaseInfo ");
            strSql.Append(" where ReceiptId=@ReceiptId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ReceiptId", DbType.Guid, ReceiptId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo GetModel(Guid ReceiptId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ReceiptId,ReceiptCode,ReceiptCityId,ReceiptCity,ReceiptCompanyId,ReceiptCompany,ReceiptDepartId,ReceiptDepart,ReceiptEmployeeId,ReceiptEmployee,BusinessType,ReceiptMoneyName,ContractId,ContractCode,HouseAddress,CustomerName,Mobile,Phone,CustomerAddress,ZipCode,GetedTime,GetedMoney,ReceiptMemo,AddEmployeeId,AddEmployee,AddTime,Status,UnusedReason,UnusedDate,UnusedPersonId,UnusedPerson,IsGeted1,IsGeted2,FinMemo,IsConfirmed,LastConfirmeTime,LastConfirmeEmpId,LastConfirmeEmployee,ConfireGetedTime,FinishFlag,LastPrintTime,LastPrintEmpId,LastPrintEmp,TotalPrintCount from t_ServiceCharge_BaseInfo ");
            strSql.Append(" where ReceiptId=@ReceiptId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "ReceiptId", DbType.Guid, ReceiptId);
            Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ReceiptId,ReceiptCode,ReceiptCityId,ReceiptCity,ReceiptCompanyId,ReceiptCompany,ReceiptDepartId,ReceiptDepart,ReceiptEmployeeId,ReceiptEmployee,BusinessType,ReceiptMoneyName,ContractId,ContractCode,HouseAddress,CustomerName,Mobile,Phone,CustomerAddress,ZipCode,GetedTime,GetedMoney,ReceiptMemo,AddEmployeeId,AddEmployee,AddTime,Status,UnusedReason,UnusedDate,UnusedPersonId,UnusedPerson,IsGeted1,IsGeted2,FinMemo,IsConfirmed,LastConfirmeTime,LastConfirmeEmpId,LastConfirmeEmployee,ConfireGetedTime,FinishFlag,LastPrintTime,LastPrintEmpId,LastPrintEmp,TotalPrintCount ");
            strSql.Append(" FROM t_ServiceCharge_BaseInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ReceiptId,ReceiptCode,ReceiptCityId,ReceiptCity,ReceiptCompanyId,ReceiptCompany,ReceiptDepartId,ReceiptDepart,ReceiptEmployeeId,ReceiptEmployee,BusinessType,ReceiptMoneyName,ContractId,ContractCode,HouseAddress,CustomerName,Mobile,Phone,CustomerAddress,ZipCode,GetedTime,GetedMoney,ReceiptMemo,AddEmployeeId,AddEmployee,AddTime,Status,UnusedReason,UnusedDate,UnusedPersonId,UnusedPerson,IsGeted1,IsGeted2,FinMemo,IsConfirmed,LastConfirmeTime,LastConfirmeEmpId,LastConfirmeEmployee,ConfireGetedTime,FinishFlag,LastPrintTime,LastPrintEmpId,LastPrintEmp,TotalPrintCount ");
            strSql.Append(" FROM t_ServiceCharge_BaseInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo> list = new List<Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo model = new Chenxin.Lib.Business.Entity.ServiceChargeBaseInfo();
            object ojb;
            ojb = dataReader["ReceiptId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReceiptId = new Guid(ojb.ToString());
            }
            model.ReceiptCode = dataReader["ReceiptCode"].ToString();
            ojb = dataReader["ReceiptCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReceiptCityId = new Guid(ojb.ToString());
            }
            model.ReceiptCity = dataReader["ReceiptCity"].ToString();
            ojb = dataReader["ReceiptCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReceiptCompanyId = new Guid(ojb.ToString());
            }
            model.ReceiptCompany = dataReader["ReceiptCompany"].ToString();
            ojb = dataReader["ReceiptDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReceiptDepartId = new Guid(ojb.ToString());
            }
            model.ReceiptDepart = dataReader["ReceiptDepart"].ToString();
            ojb = dataReader["ReceiptEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ReceiptEmployeeId = new Guid(ojb.ToString());
            }
            model.ReceiptEmployee = dataReader["ReceiptEmployee"].ToString();
            ojb = dataReader["BusinessType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BusinessType = (int)ojb;
            }
            model.ReceiptMoneyName = dataReader["ReceiptMoneyName"].ToString();
            ojb = dataReader["ContractId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractId = new Guid(ojb.ToString());
            }
            model.ContractCode = dataReader["ContractCode"].ToString();
            model.HouseAddress = dataReader["HouseAddress"].ToString();
            model.CustomerName = dataReader["CustomerName"].ToString();
            model.Mobile = dataReader["Mobile"].ToString();
            model.Phone = dataReader["Phone"].ToString();
            model.CustomerAddress = dataReader["CustomerAddress"].ToString();
            model.ZipCode = dataReader["ZipCode"].ToString();
            ojb = dataReader["GetedTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GetedTime = (DateTime)ojb;
            }
            ojb = dataReader["GetedMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.GetedMoney = (decimal)ojb;
            }
            model.ReceiptMemo = dataReader["ReceiptMemo"].ToString();
            ojb = dataReader["AddEmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddEmployeeId = new Guid(ojb.ToString());
            }
            model.AddEmployee = dataReader["AddEmployee"].ToString();
            ojb = dataReader["AddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddTime = (DateTime)ojb;
            }
            ojb = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = (int)ojb;
            }
            model.UnusedReason = dataReader["UnusedReason"].ToString();
            ojb = dataReader["UnusedDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UnusedDate = (DateTime)ojb;
            }
            ojb = dataReader["UnusedPersonId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UnusedPersonId = new Guid(ojb.ToString());
            }
            model.UnusedPerson = dataReader["UnusedPerson"].ToString();
            ojb = dataReader["IsGeted1"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsGeted1 = (bool)ojb;
            }
            ojb = dataReader["IsGeted2"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsGeted2 = (bool)ojb;
            }
            model.FinMemo = dataReader["FinMemo"].ToString();
            ojb = dataReader["IsConfirmed"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsConfirmed = (bool)ojb;
            }
            ojb = dataReader["LastConfirmeTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LastConfirmeTime = (DateTime)ojb;
            }
            ojb = dataReader["LastConfirmeEmpId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LastConfirmeEmpId = new Guid(ojb.ToString());
            }
            model.LastConfirmeEmployee = dataReader["LastConfirmeEmployee"].ToString();
            ojb = dataReader["ConfireGetedTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ConfireGetedTime = (DateTime)ojb;
            }
            ojb = dataReader["FinishFlag"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.FinishFlag = (int)ojb;
            }
            ojb = dataReader["LastPrintTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LastPrintTime = (DateTime)ojb;
            }
            ojb = dataReader["LastPrintEmpId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.LastPrintEmpId = new Guid(ojb.ToString());
            }
            model.LastPrintEmp = dataReader["LastPrintEmp"].ToString();
            ojb = dataReader["TotalPrintCount"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TotalPrintCount = (int)ojb;
            }
            return model;
        }

        /// <summary>
        /// 生成收据编号
        /// </summary>
        public static string GenerateCode(Guid CompanyId)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("usp_AutoGenerateCode");
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, CompanyId);
            db.AddInParameter(dbCommand, "CodeFlag", DbType.AnsiString, "f");
            db.AddInParameter(dbCommand, "CodeYear", DbType.AnsiString, DateTime.Now.Year.ToString().Substring(2, 2));
            db.AddOutParameter(dbCommand, "Code", DbType.AnsiString, 150);
            db.ExecuteNonQuery(dbCommand);
            return db.GetParameterValue(dbCommand, "Code").ToString();
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetPartList(int PageSize, int PageIndex, string OrderField, string TableName, string strWhere, string FieldList, string TableFieldList, bool DoCount)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("PagerMultiTable");
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "OrderField", DbType.AnsiString, OrderField);
            db.AddInParameter(dbCommand, "TableName", DbType.AnsiString, TableName);
            db.AddInParameter(dbCommand, "StrWhere", DbType.AnsiString, strWhere);
            db.AddInParameter(dbCommand, "FieldList", DbType.AnsiString, FieldList);
            db.AddInParameter(dbCommand, "TableFieldList", DbType.AnsiString, TableFieldList);
            db.AddInParameter(dbCommand, "DoCount", DbType.Boolean, DoCount);
            return db.ExecuteDataSet(dbCommand);
        }

        /// <summary>
        /// 判断是否有未收 返回true，表示通过
        /// </summary>
        public static bool CheckUnGet(string contractid)
        {
            bool flag = false;
            string strSql = "select case when ((VCommisionGeted+BCommisionGeted)>=(VRealCommisionFinal+BRealCommisionFinal)) then 'true' else 'false' end from dbo.t_Contract_CommisionInfo where ContractId='"+contractid+"'";
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            if (bool.Parse(db.ExecuteScalar(CommandType.Text, strSql).ToString()))
                flag = true;
            return flag;
        }

        /// <summary>
        /// 判断是否复核服务费核销条件 返回true，表示通过
        /// </summary>
        public static bool CheckServiceOver(string contractid)
        {
            bool flag = false;
            string strSql = "select case when (dbo.f_getServiceMoney(contractid,'')<=(dbo.f_getCommisionGeted(ContractId,'上家佣金','')+dbo.f_getCommisionGeted(ContractId,'下家佣金','')))"
            +" then 'true' else 'false' end from dbo.t_Contract_CommisionInfo where ContractId='" + contractid + "'";
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            if (bool.Parse(db.ExecuteScalar(CommandType.Text, strSql).ToString()))
                flag = true;
            return flag;
        }

        #endregion  成员方法
    }
}

